package kisti.gui.CDF;

import java.awt.Color;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;

import daniel.kisti.Helper.Caf_Helper;



/**
 * 
 * <pre>
 * kisti.gui.CDF
 *   |_ CAF_QueueStatusMon.java
 *
 * </pre>
 *
 * Desc : caf 큐 정보를 스트링형식으로 패널에 출력한다. 
 * @Company : KISTI
 * @Author :daniel
 * @Date   :2011. 11. 14. 오후 5:12:03
 * @Version:
 *
 */
public class CAF_QueueStatusMon extends JPanel implements Runnable {
	private JTextArea ta;
	private Caf_Helper cafHelper;
	private String queueStatus;;

	public CAF_QueueStatusMon() {
		// TODO Auto-generated constructor stub
		cafHelper = new Caf_Helper();

		queueStatus = getDataFromServer();
		ta = new JTextArea();
		ta.setText(queueStatus);		
		ta.setBackground(new Color(255, 204, 204));

		this.setBackground(new Color(255, 204, 204));
		this.add(ta);

		Thread t = new Thread(this);
		t.start();
	}

	public void run() {
		while (true) {
			String s1 = getDataFromServer();
			ta.setText(s1);
			try {
				Thread.sleep(1000);
			} catch (Exception e) {
			}
		}
	}

	public String getDataFromServer() {
		String result = cafHelper.getQueueStatus();
		return result;
	}
	
	
	
	
	
	
	
	

	/**
	 * Desc :
	 * 
	 * @Method Name : main
	 * @param args
	 * 
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		JFrame f = new JFrame();
		CAF_QueueStatusMon w = new CAF_QueueStatusMon();
		f.add(w);
		f.setSize(600, 284);
		f.setVisible(true);
		
		f.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}

			public void windowDeiconified(WindowEvent e) {
				System.out.println("windowDeiconified");
			}

			public void windowIconified(WindowEvent e) {
				System.out.println("windowIconified");
			}
		});
	}
}
